<?php
/**
 * Miffos framework
 * ----------------------------------------------
 *
 * Copyright (c) 2008, 2009 Martin Sadový (http://sodae.cz)
 *
 * This source file is subject to the "Miffos license" that is bundled
 * with this package in the file license.txt.
 *
 * @copyright  Copyright (c) 2008, 2009 Martin Sadový
 * @license    license.txt
 * @link       http://miffos.sodae.cz
 * @package    miffos
 * @version    $Id$
 */



abstract class Model {

    /**
     * Connection with database
     * @var object
     */
    protected $database;

    

    public function __construct(){
        if(isset(Application::get()->Config->database['connection'])){
           require_once dirname(__FILE__).'/Model/dibi.compact.php';
           $this->database = dibi::connect(Application::get()->Config->database['connection']);
        }

        if(method_exists($this, "init"))
           call_user_method("init",$this);
    }



    /**
     * Get connection with database
     * @return object
     */
    public function getConnection(){
        if($this->database instanceof dibiConnection){
            return $this->database;
        }else{
            throw new ApplicationException('You must connect to database.',4);
        }
    }
}
?>